package com.vote.dao;

import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;

import com.vote.domain.VoteComment;

@DAO(catalog = "vote")
public interface VoteCommentDAO {
	
	public static String TABLE="vote_comment";
	public static String INSERT_FIELD="comment_text,comment_time,from_user_id,to_user_id,questionnaire_id";
	public static String SELECT_FIELD=INSERT_FIELD+"comment_id";
	
	/**
	 * 根据问题id获得该问卷的所有评论
	 * @param id
	 * @return
	 */
	@SQL("select "+SELECT_FIELD+"from "+TABLE+"where questionnaire_id=:id" +
            " order by comment_time limit :offset,:length")
	   public List<VoteComment> getCommentListByQuestionnaireId(@SQLParam("id")int id, @SQLParam("offset")int offset, @SQLParam("length")int length);
	
	/**
	 * 插入评论
	 * @param comment
	 */
	@SQL("insert into "+TABLE+"("+INSERT_FIELD+") values(:model.commentText,:model.comentTime,:model.fromUserId," +
			" :model.toUserId,:model.questionnaireId)")
		public void insertComment(@SQLParam("model") VoteComment comment);
	
	/**
	 * 删除评论
	 * @param id
	 */
	@SQL("delete from "+TABLE+" where comment_id=:id")
	public void deleteComment(@SQLParam("id") int id);
	
	/**
	 * 获取刚插入comment的ID
	 * @return
	 */
	@SQL("select LAST_INSERT_ID()")
	public int getLastInsertId();

}
